package com.woniu.shop.controller;


import com.woniu.entity.Result;
import com.woniu.entity.ResultCode;
import com.woniu.shop.entity.dto.ServiceEvaluateDTO;
import com.woniu.shop.pojo.ServiceEvaluate;
import com.woniu.shop.service.IServiceEvaluateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 服务评价表 前端控制器
 * </p>
 *
 * @author malei
 * @since 2023-02-17
 */
@Api(tags = "服务评价控制器")
@RestController
@RequestMapping("/service-evaluate")
public class ServiceEvaluateController {

    @Autowired
    private IServiceEvaluateService serviceEvaluate;

    @ApiOperation("新增服务评价")
    @PostMapping("/add")
    public Result addServiceEvaluate(@RequestBody ServiceEvaluateDTO serviceEvaluateDTO){
        return serviceEvaluate.addServiceEvaluate(serviceEvaluateDTO);
    }

    @ApiOperation("根据服务ID和状态查询服务评价")
    @GetMapping("/queryServiceEvaluateById/{id}/{status}")
    public Result queryServiceEvaluateById(@PathVariable String id,@PathVariable String status){
        return serviceEvaluate.queryServiceEvaluateById(id,status);
    }
    @ApiOperation("回复服务评价")
    @PutMapping("/replyEvaluate/{id}/{message}")
    public Result replyEvaluate(@PathVariable String id,@PathVariable String message){
        return serviceEvaluate.replyEvaluate(id,message);
    }
    @ApiOperation("根据用户ID和状态查询服务评价")
    @GetMapping("/queryByUserId/{id}/{status}")
    public Result queryByUserId(@PathVariable String id,@PathVariable String status){
        return serviceEvaluate.queryByUserId(id,status);
    }

    @ApiOperation("根据ID逻辑删除评价")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable String id){
        boolean flag = serviceEvaluate.removeById(id);
        if (flag) {
            return Result.ok();
        }
        return Result.error(ResultCode.ERROR.getCode());
    }
    @ApiOperation("根据ID查询具体的评价信息")
    @GetMapping("/queryById/{id}")
    public Result queryById(@PathVariable String id){
        ServiceEvaluate evaluate = serviceEvaluate.getById(id);
        if (evaluate!=null) {
            return Result.ok(evaluate);
        }
        return Result.error(ResultCode.ERROR.getCode());
    }
}
